package niuke;

import java.util.*;

class ListNoccde {
    int val;

    ListNoccde next = null;
    public ListNoccde(int val){
        this.val=val;
    }
}
abstract class Animal{
    private String name;  //名字
    private int age;   //年龄
    public abstract void info();  //返回动物信息
    public abstract void speak(); //动物叫

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
}
class Dog extends Animal{
    public int violence;
    public Dog(String name, int age, int violence) {
        super(name, age);
        this.violence = violence;
    }
    @Override
    public void info() {
        System.out.println("该狗的名字是"+this.getName()+",年龄是"+this.getAge()+"岁,凶猛程度是"+this.violence+"度");
    }

    @Override
    public void speak() {
        System.out.println("旺旺");
    }
}
class Cat extends Animal{
    public int mousingAbility;
    public Cat(String name, int age, int mousingAbility) {
        super(name, age);
        this.mousingAbility = mousingAbility;
    }
    @Override
    public void info() {
        System.out.println("该猫的名字是"+this.getName()+",年龄是"+this.getAge()+"岁,捕鼠能力是"+this.mousingAbility+"分");
    }

    @Override
    public void speak() {
        System.out.println("喵喵");
    }
}
class Factory{
    Animal getAnimalByType(int type,String name, int age, int ownAttribute){
        if (type==1){
            return new Dog(name, age, ownAttribute);
        }
        else {
            return new Cat(name, age, ownAttribute);
        }
    }
}
class Circle{
    private double radius;
    public Circle(){
    }
    public Circle(double radius){
        this.radius=radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }
    public double getArea(){
        return Math.PI*this.getRadius()*this.getRadius();
    }
    public double getPerimeter(){
        return Math.PI*2*this.getRadius();
    }
    @Override
    public String toString() {
        return "Circle(r:"+String.format("%.2f", radius)+")";
    }
}
class Cone{
    private double height;
    private Circle circle;
    public Cone(){

    }
    public Cone(double height, Circle circle) {
        this.height = height;
        this.circle = circle;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public Circle getCircle() {
        return circle;
    }

    public void setCircle(Circle circle) {
        this.circle = circle;
    }
    public double getVolume(){
        return 1/3.00*this.getHeight()*this.getCircle().getArea();
    }

    @Override
    public String toString() {
        return "Cone(h:"+String.format("%.2f", height)+","+circle+")";
    }
}
class dada {
    private String no;
    private String name;

    public dada(String no, String name) {
        super();
        this.no = no;
        this.name = name;
    }
    public dada() {
        super();
    }
    public String getNo() {
        return no;
    }
    public void setNo(String no) {
        this.no = no;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student [no=" + no + ", name=" + name + "]";
    }
}
public class niuKeMain3 {
    public static void main1(String[] args) {
        // 创建学生对象
        dada stu1 = new dada("1001","zs");
        dada stu2 = new dada("1002","ls");

        //2考查集合接口的实例化
        //创建有序集合List，并向集合中添加学生，
        List<dada> students=new ArrayList<>();
        students.add(stu1);
        students.add(stu2);

        //计算学生人数,显示学生信息
        for(int i=0;i<students.size();i++) {
            //3考查遍历方法和向下转型
            dada stu=students.get(i);
            System.out.println("no:"+stu.getNo()+"\t name:"+stu.getName());
        }
    }
    public ListNoccde deleteDuplicates (ListNoccde head) {
        // write code here
        if (head==null){
            return null;
        }
        int tmp=1001;
        ListNoccde n1=new ListNoccde(-1);
        ListNoccde n2=head;
        ListNoccde n3=head.next;
        ListNoccde n4=n1;
        while (n3!=null){
            if (n2.val!= n3.val){
                if (n2.val!=tmp){
                    n4.next=n2;
                    n4=n4.next;
                }
            }
            if (n2.val==n3.val){
                tmp= n2.val;
            }
            if (n3.next==null){
                if (n3.val!=tmp){
                    n4.next=n3;
                    n4=n4.next;
                }
            }
            n2=n2.next;
            n3=n3.next;
        }
        n4.next=null;
        return n1.next;
    }
    public ListNoccde reverseBetween (ListNoccde head, int m, int n) {
        // write code here
        ListNoccde dummyNode=new ListNoccde(-1);
        dummyNode.next=head;
        ListNoccde pre=dummyNode;
        for (int i = 0; i < m-1; i++) {
            pre=pre.next;
        }
        ListNoccde cur=pre.next;
        ListNoccde Cur_next;
        for (int i = 0; i < n-m; i++) {
            Cur_next=cur.next;
            cur.next=Cur_next.next;
            Cur_next.next=pre.next;
            pre.next=Cur_next;
        }
        return dummyNode.next;
    }
    public String solve (String s, String t) {
        // write code here
        String str="";
        int num1=Integer.parseInt(s);
        int num2=Integer.parseInt(t);
        int sum=num1+num2;
        str=str+sum;
        return str;
    }
    public int[] twoSum (int[] numbers, int target) {
        // write code here
        int[] index=new int[2];
        for (int i = 0; i < numbers.length; i++) {
            for (int j = i+1; j < numbers.length; j++) {
                if (numbers[i]+numbers[j]==target){
                    if (numbers[i]<=numbers[j]){
                        index[1]=j+1;
                        index[0]=i+1;
                    }
                    else {
                        index[0]=i+1;
                        index[1]=j+1;
                    }
                    return index;
                }
            }
        }
        return index;
    }
    public static int[] FindNumsAppearOnce (int[] array) {
        // write code here
        HashSet<Integer> set=new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            if (set.contains(array[i])){
                set.remove(array[i]);
            }
            else {
                set.add(array[i]);
            }
        }
        int[] b=new int[2];
        int count=0;
        for (Object a:set.stream().toArray()) {
            b[count++]=(int)a;
        }
        Arrays.sort(b);
        return b;
    }

    public static void main(String[] args) {
        int[] array=new int[]{1,4,1,6};
        int[] b=FindNumsAppearOnce(array);
        for (int num:b) {
            System.out.println(num);
        }

    }
}
